package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioGroup;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 健康体检录入-第二页
 * 
 * @author houyuchun
 * 
 */
public class HealthExamThirdActivity extends AbstractControlActivity implements
		OnClickListener {

	private String createDate;
	// 饮酒类别
	private int[] checkYinjiuIds = { R.id.check_yjzl_baijiu,
			R.id.check_yjzl_pijiu, R.id.check_yjzl_hongjiu,
			R.id.check_yjzl_huangjiu };

	private RadioGroup zybwhysjcs;
	private RadioGroup dwzlfcfhcs;
	private RadioGroup fswzfhcs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_health_exam_third);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);

		addRadioGroupView(R.id.rad_xiyanzhuangkuang, "吸烟状况");

		addEditTextView(R.id.edt_rixiyanliang, "日吸烟量");
		addEditTextView(R.id.edt_kaishixynl, "开始吸烟年龄");
		addEditTextView(R.id.edt_jieyannl, "戒烟年龄");

		addRadioGroupView(R.id.rad_yinjiupinlv, "饮酒频率");

		addEditTextView(R.id.edt_riyinjiuliang, "日饮酒量");

		addRadioGroupView(R.id.rad_shifoujiejiu, "是否戒酒");

		addEditTextView(R.id.edt_jiejiunl, "戒酒年龄");
		addEditTextView(R.id.edt_kaishiyjnl, "开始饮酒年龄");

		addRadioGroupView(R.id.rad_xiongjiu, "近一年内是否曾醉酒");

		addCheckBoxView(checkYinjiuIds, "饮酒种类");
		addEditTextView(R.id.edt_yjzl_qita, "其他酒类");

		addRadioGroupView(R.id.rad_zybwhysjcs, "职业病危害因素接触史");
		addRadioGroupView(R.id.rad_dwzlfcfhcs, "毒物种类粉尘防护措施");
		addRadioGroupView(R.id.rad_fswzfhcs, "放射物质防护措施");

		zybwhysjcs = (RadioGroup) findViewById(R.id.rad_zybwhysjcs);
		dwzlfcfhcs = (RadioGroup) findViewById(R.id.rad_dwzlfcfhcs);
		fswzfhcs = (RadioGroup) findViewById(R.id.rad_fswzfhcs);
		zybwhysjcs
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						if (checkedId == R.id.rad_zybwhysjcs_no) {
							dwzlfcfhcs.check(R.id.rad_dwzlfcfhcs_no);
							fswzfhcs.check(R.id.rad_fswzfhcs_no);
						} else {
							dwzlfcfhcs.clearCheck();
							fswzfhcs.clearCheck();
						}
					}
				});

		addEditTextView(R.id.edt_gongzhongcysj, "工种从业时间");

		// Properties文件路径
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		controlManager.toControl();

		this.setButtonListener(this, R.id.btn_next, R.id.btn_previous);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		// 获取点击按钮
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_previous:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, HealthExamSecondActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.btn_next:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 保存当前信息到Bean
			intent.setClass(this, HealthExamFourthActivity.class);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}

}
